package com.imooc.diveinspringboot.mybatis.mapper;

import com.imooc.diveinspringboot.mybatis.entity.OrderEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface OrderEntityMapper {
    @Delete({
        "delete from t_order",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into t_order (id, order_no, ",
        "title, status, amount)",
        "values (#{id,jdbcType=BIGINT}, #{orderNo,jdbcType=VARCHAR}, ",
        "#{title,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, #{amount,jdbcType=INTEGER})"
    })
    int insert(OrderEntity record);

    @InsertProvider(type=OrderEntitySqlProvider.class, method="insertSelective")
    int insertSelective(OrderEntity record);

    @Select({
        "select",
        "id, order_no, title, status, amount",
        "from t_order",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="title", property="title", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
        @Result(column="amount", property="amount", jdbcType=JdbcType.INTEGER)
    })
    OrderEntity selectByPrimaryKey(Long id);

    @UpdateProvider(type=OrderEntitySqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(OrderEntity record);

    @Update({
        "update t_order",
        "set order_no = #{orderNo,jdbcType=VARCHAR},",
          "title = #{title,jdbcType=VARCHAR},",
          "status = #{status,jdbcType=INTEGER},",
          "amount = #{amount,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(OrderEntity record);
}